Skip to content

asio: a page's resolver results hold their one entry in place, so that they allocate nothing - #7

Merged
pinhopro merged 1 commit into
mainfrom
page-resolver-results
Nov 18, 2026
Merged

pinhopro merged 1 commit into
mainfrom
page-resolver-results

Conversation

@pinhopro

Copy link
Copy Markdown
Contributor

What changes

In a page, a resolution's results hold their one entry in place and allocate nothing.

A page looks up no name: its resolver keeps the host and the service for the page's transport. Its results were Boost's basic_resolver_results, which allocate with new, taking no allocator:

  • the list of entries;
  • its shared count;
  • the entry's storage;
  • and the host's two copies when it is longer than a short string holds.

That is 7 operator new for a long host and a long service, as the browser allocation test measured before this change. It was the one allocation a trystero room still made outside its resource in a page, once per relay connection.

  • ip/basic_resolver_results.hpp and ip/basic_resolver_entry.hpp are owned facades now (upstream/pin.json).
    • Natively and on WASI they still forward to Boost's types: native types keep Boost's identity.
    • In a page they define webcpp::asio::ip::basic_resolver_results and basic_resolver_entry, under Boost's names and with Boost's members.
  • The results are a forward range of at most one entry. Two results are equal when their entries are.
  • The host is held in a buffer of 254 bytes, DNS's 253 and a final dot. A longer host names nothing DNS would find, and reports host_not_found, synchronously, posted, or thrown.
  • The service is kept as the digits of its port and the count of its leading zeros. A numeric service of any length comes back exactly as it was given, as the allocation test's 38-character service always did.
  • Code that names the type keeps compiling: in a page, webcpp::asio::ip::tcp::resolver::results_type and webcpp::asio::ip::basic_resolver_results<tcp> are the same new type. Only code that names Boost's type for a page, or treats its results as an iterator, as Boost's deprecated interface allows, breaks. The changelog marks the change as breaking.

Tests

  • resolver_test, in a page, covers:
    • that the type is the one under Boost's names;
    • the forward range;
    • copies, moves and swap;
    • equality;
    • names returned in an allocator's string;
    • the longest host, a longer one refused three ways;
    • services with many leading zeros.
  • allocation_test, in a page: a long host and a long service resolve, copy and post with no operator new and no C library allocation; before the change, 7 operator new each way.

Verified locally

  • libs/asio/test on emscripten: every test passed, the alone header tests among them. The only failures in the log are the compile-fail tests, whose errors are expected.
  • The asyncify and no-exceptions variants of resolver and allocation.
  • libs/asio/test natively: every test passed.
  • The alone tests of the three resolver headers on wasip2 and wasip3.
  • libs/beast/test and libs/trystero/test on emscripten, with this change. trystero's relay allocation test then expects no resolver allocation, in a separate trystero PR.
  • upstream/sync.py --check, clang-format, clang-tidy over the touched units, and the lint's pattern rules.

🤖 Generated with Claude Code

…t resolving, copying and posting them allocate nothing

A page resolves no name, and Boost's results took seven operator new for a long host and
service: the list, its shared count, the entry's storage and the names' copies. In a page,
ip/basic_resolver_results.hpp and ip/basic_resolver_entry.hpp are now owned facades that define
webcpp's own types under Boost's names, with the host in a buffer of 254 bytes, DNS's 253 and a
final dot, and the service as its port's digits and its leading zeros. A longer host reports
host_not_found. Natively and on WASI both headers still forward to Boost's.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant